﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Backend.Data.Entities;
using System.Data.Entity;

namespace Backend.Data.Managers
{
    public class NaturalPersonManger
    {
        public static IEnumerable<NaturalPerson> GetAll()
        {
            using (BackendDbContext db = new BackendDbContext())
            {
                //return from s in c.States select s; // 
                return db.NaturalPersons.AsEnumerable();
            }
        }

        public static List<NaturalPerson> GetList()
        {
            using (BackendDbContext db = new BackendDbContext())
            {
                //return from s in c.States select s;
                return db.NaturalPersons.ToList();
            }
        }

        public static NaturalPerson FindByName(string firstName, string lastName )
        {
            using (BackendDbContext db = new BackendDbContext())
            {
                //return from p in db.NaturalPersons where p.FirstName==firstName && p.LastName == lastName select p; 
                return db.NaturalPersons.Where(p => p.FirstName==firstName && p.LastName == lastName).First(); 
            }
        }

        public static NaturalPerson FindByDate(string birthdate, string photo) 
        {
            using (BackendDbContext db = new BackendDbContext() )
            {
                return db.NaturalPersons.Where(p => p.BirthDate==birthdate && p.Photo == photo).First();
            }
        }

        public static NaturalPerson Create(NaturalPerson naturalPerson)
        {
            using (BackendDbContext db = new BackendDbContext())
            {

                NaturalPerson naturalPersonDB =db.NaturalPersons.Add(naturalPerson);
                db.SaveChanges();


                return naturalPersonDB;
            }
        }
    }
}
